1 /*
2 
3 Boost Software License - Version 1.0 - August 17th, 2003
4 
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */ 
28 
29 module derelict.glib.gmem;
30 
31 import derelict.glib.gtypes;
32 import derelict.glib.glibconfig;
33 import core.stdc.config;
34 
35 extern (C):
36 
37 alias _GMemVTable GMemVTable;
38 
39 version(Derelict_Link_Static)
40 {
41     //extern( C ) __gshared 
42     //{
43     //    gboolean g_mem_gc_friendly;
44     //    GMemVTable* glib_mem_profiler_table;
45     //}
46 }
47 else
48 {
49     extern( C ) nothrow 
50     {
51         alias da_g_mem_gc_friendly = gboolean;
52         alias da_glib_mem_profiler_table = GMemVTable*;
53     }
54 
55     __gshared
56     {
57         da_g_mem_gc_friendly g_mem_gc_friendly;
58         da_glib_mem_profiler_table glib_mem_profiler_table;
59     }
60 }
61 
62 
63 struct _GMemVTable
64 {
65 	gpointer function (gsize) malloc;
66 	gpointer function (gpointer, gsize) realloc;
67 	void function (gpointer) free;
68 	gpointer function (gsize, gsize) calloc;
69 	gpointer function (gsize) try_malloc;
70 	gpointer function (gpointer, gsize) try_realloc;
71 }
72 
73 version(Derelict_Link_Static)
74 {
75     extern( C ) nothrow 
76     {
77         void g_free(gpointer mem);
78         gpointer g_malloc(gsize n_bytes);
79         gpointer g_malloc0(gsize n_bytes);
80         gpointer g_realloc(gpointer mem, gsize n_bytes);
81         gpointer g_try_malloc(gsize n_bytes);
82         gpointer g_try_malloc0(gsize n_bytes);
83         gpointer g_try_realloc(gpointer mem, gsize n_bytes);
84         gpointer g_malloc_n(gsize n_blocks, gsize n_block_bytes);
85         gpointer g_malloc0_n(gsize n_blocks, gsize n_block_bytes);
86         gpointer g_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes);
87         gpointer g_try_malloc_n(gsize n_blocks, gsize n_block_bytes);
88         gpointer g_try_malloc0_n(gsize n_blocks, gsize n_block_bytes);
89         gpointer g_try_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes);
90         void g_mem_set_vtable(GMemVTable* vtable);
91         gboolean g_mem_is_system_malloc();
92         void g_mem_profile();
93     }
94 }
95 else
96 {
97     extern( C ) nothrow 
98     {
99         alias da_g_free = void function(gpointer mem);																
100         alias da_g_malloc = gpointer function(gsize n_bytes);														
101         alias da_g_malloc0 = gpointer function(gsize n_bytes);														
102         alias da_g_realloc = gpointer function(gpointer mem, gsize n_bytes);										
103         alias da_g_try_malloc = gpointer function(gsize n_bytes);													
104         alias da_g_try_malloc0 = gpointer function(gsize n_bytes);													
105         alias da_g_try_realloc = gpointer function(gpointer mem, gsize n_bytes);									
106         alias da_g_malloc_n = gpointer function(gsize n_blocks, gsize n_block_bytes);								
107         alias da_g_malloc0_n = gpointer function(gsize n_blocks, gsize n_block_bytes);								
108         alias da_g_realloc_n = gpointer function(gpointer mem, gsize n_blocks, gsize n_block_bytes);				
109         alias da_g_try_malloc_n = gpointer function(gsize n_blocks, gsize n_block_bytes);							
110         alias da_g_try_malloc0_n = gpointer function(gsize n_blocks, gsize n_block_bytes);							
111         alias da_g_try_realloc_n = gpointer function(gpointer mem, gsize n_blocks, gsize n_block_bytes);			
112         alias da_g_mem_set_vtable = void function(GMemVTable* vtable);												
113         alias da_g_mem_is_system_malloc = gboolean function();														
114         alias da_g_mem_profile = void function();																	
115     }
116 
117     __gshared
118     {
119 	    da_g_free g_free; 
120         da_g_malloc g_malloc; 
121         da_g_malloc0 g_malloc0; 
122         da_g_realloc g_realloc; 
123         da_g_try_malloc g_try_malloc; 
124         da_g_try_malloc0 g_try_malloc0; 
125         da_g_try_realloc g_try_realloc; 
126         da_g_malloc_n g_malloc_n; 
127         da_g_malloc0_n g_malloc0_n; 
128         da_g_realloc_n g_realloc_n; 
129         da_g_try_malloc_n g_try_malloc_n; 
130         da_g_try_malloc0_n g_try_malloc0_n; 
131         da_g_try_realloc_n g_try_realloc_n; 
132         da_g_mem_set_vtable g_mem_set_vtable; 
133         da_g_mem_is_system_malloc g_mem_is_system_malloc; 
134         da_g_mem_profile g_mem_profile; 
135     }
136 }